var app = getApp();
const util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    size: 10,
    isFirst: true,
    list: [],
    box:[]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  backindex: function () {
    wx.reLaunch({
      url: '/pages/index/index',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.setData({
      page: 1,
      size: 10,
      list: [],
      isFirst: true
    });
    let data = {
      page: this.data.page,
      size: this.data.size,
      ztype: 1,
      openid: app.globalData.openid
    }
    util.http(app.globalData.userRecord, 'POST', data, this.porcessData)
    wx.showNavigationBarLoading();
    wx.showLoading();

  },
  porcessData: function(res) {
    console.log(res);
    let list = res.data.records;
    let totalList = [];
    if (!this.data.isFirst) {
      if (list.length < 1) {
        wx.showToast({
          title: '没有更多数据了',
          icon: 'none',
          duration: 2000
        })
      }
      totalList = this.data.list.concat(list);
      console.log(totalList);
    } else {
      totalList = list;
      this.data.isFirst = false;
    }
    var b = {}
    var newList = [];
    totalList.forEach(v => {
      !b[v.favorTime] ? b[v.favorTime] = [v] : b[v.favorTime].push(v);
    })
    console.log(b);
    var i = 0;
    for (var o in b) {
      newList[i] = {
        "time": o,
        "oarr": b[o]
      }
      i++;
    }
    this.setData({
      list: totalList,
      box: newList
    })
    console.log(newList);



    wx.hideNavigationBarLoading();
    wx.hideLoading();
  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var page = this.data.page;
    page++;
    this.setData({
      page: page
    });
    let data = {
      page: this.data.page,
      size: this.data.size,
      ztype: 1,
      openid: app.globalData.openid
    }
    util.http(app.globalData.userRecord, 'POST', data, this.porcessData)
    wx.showNavigationBarLoading();
    wx.showLoading();
  },

   /**
   * 用户点击右上角分享
   
  onShareAppMessage: function() {

  }
  */
})